import 'package:flutter/material.dart';

abstract class RefreshableWidget extends StatefulWidget {
  RefreshableWidget({Key? key})
      : super(key: key is GlobalKey ? key : GlobalKey());

  void reload() {
    if (key is! GlobalKey) {
      return;
    }

    final akey = key as GlobalKey;
    akey.currentState!.setState(() {});
  }
}

class RefreshableView extends RefreshableWidget {
  final Widget Function(BuildContext context) builder;

  RefreshableView({Key? key, required this.builder}) : super(key: key);

  @override
  _RefreshableViewState createState() => _RefreshableViewState();
}

class _RefreshableViewState extends State<RefreshableView> {
  @override
  Widget build(BuildContext context) {
    return widget.builder(context);
  }
}
